package model;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.InvalidPropertiesFormatException;
import java.util.Properties;

public class MyProperties {

	public static final String CONFIG_PATH = "ressources/conf.xml";
	
	private static volatile MyProperties instance = null;

	private Properties properties = null;

	public static MyProperties getInstance(){
		if(MyProperties.instance == null){
			synchronized(MyProperties.class) {
				if (MyProperties.instance == null) {
					MyProperties.instance = new MyProperties();
				}
			}
		}
		return MyProperties.instance;
	}
	
	protected MyProperties() {
		FileInputStream fin = null;
		try {
			properties = new Properties();
			fin = new FileInputStream(new File(CONFIG_PATH));
			properties.loadFromXML(fin);
			//System.out.println(properties.getProperty("xmlout"));
		} catch (InvalidPropertiesFormatException e) {
			e.printStackTrace();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (fin != null){
				try {
					fin.close();
				} catch (IOException ex) {
					ex.printStackTrace();
				}
			}
		}
	}
	
	public Properties getProperties(){
		return properties;
	}
	
}
